package stack_queue;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description: 232. 用栈实现队列
 * User: Li_yizYa
 * Date: 2025/5/17
 * Time: 22:37
 */
public class Solution1 {

    // 首先定义两个栈
    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    // Solution 代表 myQueue
    public Solution1() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int peek() {
        dumpStackIn();
        return stackOut.peek();
    }

    public int pop() {
        dumpStackIn();
        return stackOut.pop();
    }

    public boolean empty() {
        return stackOut.isEmpty() && stackIn.isEmpty();
    }

    /**
     * 当 stackOut 为空时，将 stackIn 中的元素插入 stackOut 中
     */
    public void dumpStackIn() {
        if (!stackOut.isEmpty()) {
            return;
        }
        while (!stackIn.isEmpty()) {
            stackOut.push(stackIn.pop());
        }
    }

    public static void main(String[] args) {

    }
}
